﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.ActiveRecord;
using Castle.Components.Validator;
using MiragePWF.NH.Validation;
using Wolfut.MirageEE.Kernal.Common;
using Wolfut.MirageEE.Domain.CommonUtilities;

namespace Wolfut.MirageEE.Domain.Common
{
    [ActiveRecord("CODE_RULES")]
    [Serializable]
    public  class CodeRule : PersistentObjectWithGuid
    {
        #region 编码前缀
        /// <summary>
        /// 编码前缀
        /// </summary>
        [Property("CODE_PREFIX")]      
        [ValidateNonEmpty, ValidateLength(0, 20, "编码前缀超长！")]
        [ValidateIsUniqueInSameTransactionWithString(true, "数据库已经存在相同的编码前缀！")]
        public virtual string CodePre
        {
            get
            {
                return codePre;
            }
            set
            {
                codePre = value;
            }
        }
        private string codePre;
        #endregion

        #region 编码名称
        /// <summary>
        /// 编码名称
        /// </summary>
        [Property("RULE_NAME")] 
        [ValidateNonEmpty, ValidateLength(0, 40, "编码名称超长！")]
        public virtual string RuleName
        {
            get
            {
                return ruleName;
            }
            set
            {
                ruleName = value;
            }
        }
        private string ruleName;
        #endregion

        #region 是否默认
        /// <summary>
        /// 是否默认
        /// </summary>
        [Property("ID_DEFAULT")]        
        public virtual Boolean IsDefault
        {
            get
            {
                return isDefault;
            }
            set
            {
                isDefault = value;
            }
        }
        private Boolean isDefault;
        #endregion

        #region 流水号位数
        /// <summary>
        /// 流水号位数
        /// </summary>
        [Property("NUMBER_WIDTH")] 
        public virtual int RuleWidth
        {
            get
            {
                return ruleWidth;
            }
            set
            {
                ruleWidth = value;
            }
        }
        private int ruleWidth;
        #endregion

        #region 起始流水号
        /// <summary>
        /// 起始流水号
        /// </summary>
        [Property("START_NUMBER")] 
        public virtual Int32 StartNo
        {
            get
            {
                return startNo;
            }
            set
            {
                startNo = value;
            }
        }
        private Int32 startNo;
        #endregion

        #region 编码方式
        /// <summary>
        /// 编码方式：流水号、年编号、月编号、日编号
        /// </summary>
        [Property("CODE_MODE")] 
        public virtual CodeManner CodeManner
        {
            get
            {
                return codeManner;
            }
            set
            {
                codeManner = value;
            }
        }
        private CodeManner codeManner=CodeManner.No;
        #endregion

        #region 年位数
        /// <summary>
        /// 年位数
        /// </summary>
        [Property("YEAR_WIDTH")] 
        public virtual Int16 YearWidth
        {
            get
            {
                return yearWidth;
            }
            set
            {
                yearWidth = value;
            }
        }
        private Int16 yearWidth;
        #endregion      

        #region 编码标识
        /// <summary>
        /// 编码标识
        /// </summary>
        [Property("CODE_FLAG")] 
        [ValidateNonEmpty, ValidateLength(0, 20, "编码标识超长！")]
        public virtual string CodeFlag
        {
            get
            {
                return locationFlag;
            }
            set
            {
                locationFlag = value;
            }
        }
        private string locationFlag;
        #endregion

        #region 逻辑删除
        private Boolean isDeleted=false;
        [Property("IS_DELETED")]
        public virtual Boolean IsDeleted
        {
            get
            {
                return isDeleted;
            }
            set
            {
                isDeleted = value;
            }
        }
        #endregion

        #region 最新编码
        /// <summary>
        /// 最新编码
        /// </summary>
        [Property("LAST_CODE")]
        public virtual string LastCode
        {
            get
            {
                return lastCode;
            }
            set
            {
                lastCode = value;
            }
        }
        private string lastCode;
        #endregion
    }
}
